package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProUnitBean;
import com.xoms.admin.persist.dao.ProUnitDao;
import com.xoms.util.StringUtil;

@Repository
public class ProUnitImpl extends BaseImpl implements ProUnitDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProUnitMapper";

	@Override
	public int selectCount(String key) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);
	}

	@Override
	public List<ProUnitBean> selectList(String key, int page, int pagesize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pagesize);
		params.put("length", pagesize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}

		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public ProUnitBean selectOneByName(String name) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByName", name);
	}

	@Override
	public int insert(ProUnitBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(ProUnitBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public ProUnitBean selectOneById(Integer uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", uid);
	}

	@Override
	public int selectCount2Unit(int uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount2Unit", uid);
	}

	@Override
	public int del(int uid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", uid);
	}

	@Override
	public int updateStatus(int uid, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateStatus", params);
	}



}
